home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / SampleSMSAMServer / DebuggingWindows.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  5.4 KB  |  218 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DebuggingWindows.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __DEBUGGINGGEAR__
  15. #include "DebuggingGear.h"
  16. #endif
  17.  
  18. #ifndef __DEBUGSTREAM__
  19. #include "DebugStream.h"
  20. #endif
  21.  
  22. #ifndef __DEBUGGINGWINDOWS__
  23. #include "DebuggingWindows.h"
  24. #endif
  25.  
  26. #ifndef __FONTS__
  27. #include <Fonts.h>
  28. #endif
  29.  
  30. #ifndef __MEMORY__
  31. #include <Memory.h>
  32. #endif
  33.  
  34. #ifndef __TRANSCRIPTWINDOW__
  35. #include "TranscriptWindow.h"
  36. #endif
  37.  
  38. #ifndef __RESOURCES__
  39. #include <Resources.h>
  40. #endif
  41.  
  42. #ifndef __STDIO__
  43. #include <stdio.h>
  44. #endif
  45.  
  46. #ifndef __UTILITIES__
  47. #include "Utilities.h"
  48. #endif
  49.  
  50. #ifndef __WINDOWS__
  51. #include <Windows.h>
  52. #endif
  53.  
  54. #ifndef __WRITELINEWINDOW__
  55. #include "WriteLineWindow.h"
  56. #endif
  57.  
  58. /***********************************|****************************************/
  59.  
  60. Boolean GetDefaultWindowInformation ( short dialogID, Boolean& visible, Rect & screenRect );
  61. Boolean RectOnScreen ( const Rect & rect );
  62.  
  63. extern short    gApplicationFile;
  64.  
  65. /***********************************|****************************************/
  66.  
  67. #pragma segment Initialize
  68. void InitializeDebuggingWindows()
  69. {
  70.     Rect where;
  71.     Boolean visible;
  72.  
  73. #if 0    
  74.     WWInit (240, 80);
  75.  
  76.     // Initialize the debugging window stuff
  77.     {    short            debugFont;
  78.         Rect            bounds;
  79.         unsigned long    currentTime;
  80.  
  81.         GetDateTime (¤tTime);
  82.         SetRect (&bounds, 16, 40, 16+80*6+16, 40+32*12+16);
  83.  
  84.         GetFNum ("\pASCII Courier", &debugFont);
  85.         if (debugFont == 0)
  86.             GetFNum ("\pMonaco", &debugFont);
  87.  
  88.         Rect where;
  89.         Boolean visible;
  90.         if ( GetDefaultWindowInformation ( -1, visible, where ) && RectOnScreen ( where ) )
  91.             WWNew ( & where, "\pBovineServer Log", true, visible, debugFont, 10 );
  92.         else
  93.             WWNew(&bounds, "\pBovineServer Debug", true, true, debugFont, 10);
  94.  
  95.         //    Create a 
  96.         {
  97.             DateTimeRec now;
  98.             GetTime ( & now );
  99.             
  100.             Str255 logFileName;
  101.             
  102.             logFileName[0] = sprintf ( (char*) logFileName,
  103.                                          "*BS Log %02d%02d%02d %02d%02d",
  104.                                          now.year % 100,
  105.                                          now.month, now.day,
  106.                                          now.hour, now.minute ) - 1 ;
  107.  
  108.             extern short gBovineWorkingVRefNum;                                         
  109.             extern unsigned long gBovineWorkingDirID;
  110.             unsigned long gBovineServerLogFileDirectory =
  111.                 CreateFolderIfItDoesntExist ( gBovineWorkingVRefNum, gBovineWorkingDirID, "\pBovineServer Logs" );
  112.                 
  113.             WWRedirect (gBovineWorkingVRefNum, gBovineServerLogFileDirectory, logFileName );
  114.             
  115.             if ( keithFlag.Flag ( 24 ) )
  116.                 DeleteFilesInFolderOlderThan ( gBovineServerLogFileDirectory, gBovineServerLogFileDirectory, NowDateTime() - 3*60*60*24 );
  117.         }
  118.         
  119.         //    Make the debugging window font non-purgeable
  120.         Handle fondHandle = GetResource ('FOND', debugFont);
  121.         if (fondHandle) 
  122.             HNoPurge(fondHandle);
  123.         
  124.         Handle fontHandle = GetResource ('FONT', debugFont);
  125.         if (fontHandle) HNoPurge(fontHandle);
  126.  
  127.         // Put the time we started into the debugging window
  128.         keith << 
  129.                 "BLJ started at "
  130.                                              << date << " " << time << endl;
  131.     }
  132.  
  133. #else
  134.  
  135.     extern TTranscriptWindow * gTranscriptWindow;
  136.     
  137.     if ( ! gTranscriptWindow )
  138.     {
  139.         gTranscriptWindow = new TTranscriptWindow ( 2000 );
  140.         gTranscriptWindow->Show ();
  141.     }
  142.         
  143.     // Initialize the debugging window stuff
  144.     {    
  145.         Rect where;
  146.         Boolean visible;
  147.  
  148.         //    Create a name for the log window.
  149.         {
  150.             DateTimeRec now;
  151.             GetTime ( & now );
  152.             
  153.             Str255 logFileName;
  154.             
  155.             logFileName[0] = sprintf ( (char*) logFileName,
  156.                                          "*BS Log %02d%02d%02d %02d%02d",
  157.                                          now.year % 100,
  158.                                          now.month, now.day,
  159.                                          now.hour, now.minute ) - 1 ;
  160.  
  161.             extern short gBovineWorkingVRefNum;                                         
  162.             extern unsigned long gBovineWorkingDirID;
  163.             unsigned long gBovineServerLogFileDirectory =
  164.                 CreateFolderIfItDoesntExist ( gBovineWorkingVRefNum, gBovineWorkingDirID, "\pBovineServer Logs" );
  165.             
  166.             SetWTitle ( gTranscriptWindow->GetWindowPtr(), logFileName );
  167.             
  168.             gTranscriptWindow->Redirect (gBovineWorkingVRefNum, gBovineServerLogFileDirectory, logFileName );
  169.             
  170.             if ( keithFlag.Flag ( 24 ) )
  171.                 DeleteFilesInFolderOlderThan ( gBovineServerLogFileDirectory, gBovineServerLogFileDirectory, NowDateTime() - 3*60*60*24 );
  172.         }
  173.         
  174.         // Put the time we started into the debugging window
  175.         keith << 
  176.                 "BLJ started at " << date << " " << time << endl;
  177.  
  178.         //    Get the 'vers' resource, so we can display it too
  179.         
  180.         short savedResFile = CurResFile();
  181.         UseResFile(gApplicationFile);
  182.         Handle versionResource = Get1Resource ('vers', 1);
  183.         Str255 versionString = "\p, no version string";
  184.         short    nonReleaseRevNumber;
  185.  
  186.         if (versionResource)
  187.         {
  188.             HLock (versionResource);
  189.             NumVersion    *versionRec = (NumVersion *) *versionResource;
  190.     
  191.             char devCode = '?';
  192.             nonReleaseRevNumber = 10 * (versionRec->nonRelRev >> 4) + (versionRec->nonRelRev & 0xF);
  193.             switch (versionRec->stage)
  194.             {
  195.                 case developStage:    devCode = 'd'; break;
  196.                 case alphaStage: devCode = 'a'; break;
  197.                 case betaStage: devCode = 'b'; break;
  198.                 case finalStage: devCode = 'f'; break;
  199.             }
  200.     
  201.             versionString[0] = sprintf ((char *) versionString, "* version resource %d.%d.%d%c%d", 
  202.                 versionRec->majorRev, 
  203.                 versionRec->minorAndBugRev >> 4,
  204.                 versionRec->minorAndBugRev & 0xF, 
  205.                 devCode,
  206.                 nonReleaseRevNumber)
  207.                  - 1;
  208.             ReleaseResource (versionResource);
  209.         }
  210.         UseResFile (savedResFile);
  211.         keith << "Application name is " << LMGetCurApName() << versionString << endl;
  212.     }
  213.  
  214. #endif
  215. }
  216.  
  217. /***********************************|****************************************/
  218.